package cn.ccccltd.waf.id_generator.web.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.ccccltd.waf.id_generator.config.model.ResultData;
import cn.ccccltd.waf.id_generator.config.sql.param.QueryParams;
import cn.ccccltd.waf.id_generator.error.StateCode;
import cn.ccccltd.waf.id_generator.web.user.dao.UserMapper;
import cn.ccccltd.waf.id_generator.web.user.service.UserService;
import cn.ccccltd.waf.id_generator.web.user.vo.User;

@Component
public class UserServiceImpl implements UserService{

	@Autowired
	UserMapper userMapper;

	@Override
	public ResultData getByPage(QueryParams queryParams) {
		
		PageHelper.startPage(queryParams.getPageNum(), queryParams.getPageSize());
		
		//传递查询的bean，目的为了拼接sql
		User user = new User();
		
		List<User> byPage = userMapper.getUserByPage(queryParams,user);
		
		PageInfo<User> page = new PageInfo<User>(byPage);
		
		return new ResultData(StateCode.SUCCESS_CODE, StateCode.SUCCESS_CODE_MSG, page);
		
	}

	@Override
	public ResultData insert(User user) {
		
		 int insert = userMapper.insert(user);
		
		 return new ResultData(StateCode.SUCCESS_CODE, StateCode.SUCCESS_CODE_MSG, insert);
		
	}

	@Override
	public ResultData delete(User user) {
		
		 int delete = userMapper.delete(user);
		
		return new ResultData(StateCode.SUCCESS_CODE, StateCode.SUCCESS_CODE_MSG, delete);
		
	}
	
	@Override
	public ResultData update(User user) {

		int update = userMapper.update(user);
		
		return new ResultData(StateCode.SUCCESS_CODE, StateCode.SUCCESS_CODE_MSG, update);
		
	}

	@Override
	public ResultData get(User user) {
		
		User returnUser = userMapper.get(user);
		
		return new ResultData(StateCode.SUCCESS_CODE, StateCode.SUCCESS_CODE_MSG, returnUser);
		
	}

	@Override
	public List<User> getAll() {
		
		List<User> all = userMapper.getAll();
		
		return all;
	}
	
}
